   window.fbAsyncInit = function() {
        // init the FB JS SDK
        FB.init({
          appId      : '645356518812956', // App ID from the App Dashboard
          status     : true, // check the login status upon init?
          cookie     : true, // set sessions cookies to allow your server to access the session?
          xfbml      : true,  // parse XFBML tags on this page?
          frictionlessRequests: true,
          oauth  : true  /* oAuth is required now */
        });
        // Additional init code here
      }
      function login() {
        FB.login(function(response) {
          if (!response || response.error) {
            window.location.reload();
          } else if (response.authResponse) {
            // connected
          }
            else {
              // cancelled
            }
        }
                 //  ask for  {
                 //   these permissions  when needed   scope: 'publish_stream'}
                );}  
      function checkStatus(){
        FB.login(function(response) {
          console.log(response);
        }, {scope: 'publish_stream'});
           }
                 // Load the SDKs source Asynchronously
                 // Note that the debug version is being actively developed and might
                 // contain some type checks that are overly strict.
                 // Please report such bugs using the bugs tool.
                 (function(d, debug){
                   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
                   if (d.getElementById(id)) {
                     return;
                   }
                   js = d.createElement('script'); js.id = id; js.async = true;
                                        js.src = '//connect.facebook.net/en_US/all" + (debug ? "/debug" : ") + ".js';
                                        ref.parentNode.insertBefore(js, ref);
                 }
                  (document, /*debug*/ false));
        $(function(){
          $(".postable img:not(.gif), .postIt").click(function() {
            checkStatus();
            var fav = $(this).attr('src');
                                   $('#sourceHolder').html(fav);
                                   $('#uploadingPhoto,#userInput').empty();
                                   $(".photo-uploader").fadeToggle(500);
            var photoToUpload = document.getElementById('uploadingPhoto');
                                                        var userComment = document.getElementById('userInput');
                                                        var inputBox = document.createElement("textarea");
            var oImg=document.createElement("img");
            var imgURL = document.getElementById("sourceHolder");
            oImg.src = fav;
            oImg.className = 'funnyPhoto';
            inputBox.className = 'userMessage';
            inputBox.placeholder = 'Say something about this photo ...';
            inputBox.autofocus = 'autofocus';
            photoToUpload.appendChild(oImg);
            userComment.appendChild(inputBox);
          });
        });
        function post() {
          var imgURL = document.getElementById("sourceHolder");
          var userMessage = $(".userMessage").val();
          FB.api('/me/photos', 'post', {
                 message: userMessage,
                 url: imgURL.innerHTML        
                 }, function(response){
            if (!response || response.error) {
              if (response.status === 'connected') {
                  window.location.reload();
            }   
            else if ( response.status === 'not_authorized') {
                     login()
              }
              else {
                login()
              }  
          } else {
            confirmPost();
          }
        });
      }
      FB.Event.subscribe('auth.login', function(response) {
                         window.location.reload();
      });
      function postToPage() {
        var imgURL = document.getElementsByTagName("img")[0].src;
        var wallPost = {
          access_token: "CAAJK8sYOrRwBAHUCFdmCGpuy7yRl2MciWsVFQTYv36oLQLEJBVv6ZB3K6L29ZBqjcAdhdTe0v8mhPsbjAeZCuFyQiYs9KZB2Kz7ELhJQMbW5KvHGK2xeB8IZBKvuapybjp4NyfGiB0F8U3kKAxq2JTbZBeFqofxu77WN7tverLl2YJtZCwDG27OkpSdldZBRAQYZD",
          url: imgURL
        };
        FB.api('/me/photos', 'post', wallPost, function(response) {
               if (!response || response.error) {
          alert('Error occurred');
                } else {
                $(document).ready(function() {
            $(".confirmScreen").fadeIn("slow").delay(2500).fadeOut("fast");
          });
        }
      });
      }